package com.red.wood.common.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.red.wood.common.dao.ISequnceDao;

@Repository
public class SequnceDaoImpl implements ISequnceDao{

	@Autowired
	@Qualifier("jdbcTemplate")
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public String nextVal(String seqName) {
		String sql = "select nextVal('"+seqName+"') seq";
		List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
		String seq = "";
		if(list != null && list.size() > 0 ){
			seq = String.valueOf(list.get(0).get("seq"));
		}
		return seq;
	}

	@Override
	public String currentVal(String seqName) {
		String sql = "select currentVal('"+seqName+"') seq";
		List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
		String seq = "";
		if(list != null && list.size() > 0 ){
			seq = String.valueOf(list.get(0).get("seq"));
		}
		return seq;
	}

}
